package com.neudu.glsb.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neudu.glsb.dto.EmployeeAttendanceVO;
import com.neudu.glsb.pojo.EmployeeAttendance;

import com.neudu.glsb.service.EmployeeAttendanceService;
import com.neudu.glsb.mapper.EmployeeAttendanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;

/**
* @author Lenovo
* @description 针对表【employee_attendance(员工考勤信息)】的数据库操作Service实现
* @createDate 2025-04-16 22:28:32
*/
@Service
public class EmployeeAttendanceServiceImpl extends ServiceImpl<EmployeeAttendanceMapper, EmployeeAttendance>
    implements EmployeeAttendanceService {
    @Autowired
    private EmployeeAttendanceMapper employeeAttendanceMapper;
    @Override
    public void addCheckInRecord(EmployeeAttendance attendance) {
        baseMapper.insert(attendance);
    }

    @Override
    public int getLateCountByEmployeeId(Integer employeeId) {
        return employeeAttendanceMapper.getLateCountByEmployeeId(employeeId);
    }

    /**
     * 检查用户当天是否已签到
     */
    @Override
    public boolean isTodaySigned(Integer employeeId) {
        // 获取当天日期（格式：yyyy-MM-dd）
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        int signCount = employeeAttendanceMapper.checkTodaySign(employeeId, today);
        return signCount > 0;
    }

    /**
     * 获取用户历史签到记录
     */
    @Override
    public List<EmployeeAttendance> getHistorySign(Integer employeeId) {
        return employeeAttendanceMapper.getHistorySign(employeeId);
    }

    @Override
    public IPage<EmployeeAttendanceVO> getAllAttendance(int pageNum, int pageSize) {
        Page<EmployeeAttendanceVO> page = new Page<>(pageNum, pageSize);
        return employeeAttendanceMapper.getAllAttendance(page);
    }
    }
